package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class NursingProjectServiceimpl implements NursingProjectService {

    @Autowired
    NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse selectAll(String name, Integer status, Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum,pageSize);
        Page<NursingProjectVo> page = nursingProjectMapper.selectAll(name,status);
        PageResponse pageResponse=new PageResponse();
        pageResponse.setRecords(page.getResult());
        pageResponse.setTotal(page.getTotal());
        pageResponse.setPageSize(pageSize);
        pageResponse.setPage(pageNum);
        pageResponse.setPages(Long.valueOf(pageSize));
        return pageResponse;

    }

    @Override
    public void addNursing(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject =new NursingProject();
        BeanUtil.copyProperties(nursingProjectDto,nursingProject);
        nursingProjectMapper.insertNursing(nursingProject);
    }

    @Override
    public NursingProjectVo selectById(Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectMapper.selectById(id);
        return nursingProjectVo;

    }

    @Override
    public void update(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject =new NursingProject();
        BeanUtil.copyProperties(nursingProjectDto,nursingProject);
        nursingProjectMapper.update(nursingProject);
    }

    @Override
    public void updateStatus(Long id, Integer status) {
        nursingProjectMapper.updateStatus(id,status);
    }

    @Override
    public void deleteById(Long id) {
        nursingProjectMapper.deleteById(id);
    }

    @Override
    public List<NursingProjectVo> selectAllNur() {
        List<NursingProjectVo> nursingProjectVos =  nursingProjectMapper.selectAllNur();
        return nursingProjectVos;
    }
}
